with Interfaces.C.Pointers;
with Ada.Unchecked_Conversion;

package body FT2.Image is

   package Vector_Pointers is new Interfaces.C.Pointers
     (Natural, FT_Vector, FT_Vector_Array, (0, 0));

   package Curve_Tag_Pointers is new Interfaces.C.Pointers
     (Natural, FT_Curve_Tag, FT_Curve_Tag_Array, 0);

   package Span_Pointers is new Interfaces.C.Pointers
     (Natural, FT_Span, FT_Span_Array, (0, 0, 0));

   ------------
   -- To_Pos --
   ------------

   function To_Pos (X : FT_Long) return FT_Pos is
   begin
      return FT_Pos (X);
   end To_Pos;

   ------------
   -- To_Pos --
   ------------

   function To_Pos (X : FT_F26Dot6) return FT_Pos is
      function Internal is new Ada.Unchecked_Conversion (FT_F26Dot6, FT_Pos);
   begin
      return Internal (X);
   end To_Pos;

   ------------
   -- To_Pos --
   ------------

   function To_Pos (X : FT_Fixed) return FT_Pos is
      function Internal is new Ada.Unchecked_Conversion (FT_Fixed, FT_Pos);
   begin
      return Internal (X);
   end To_Pos;

   -------------
   -- To_Long --
   -------------

   function To_Long (X : FT_Pos) return FT_Long is
   begin
      return FT_Long (X);
   end To_Long;

   ----------------
   -- To_F26Dot6 --
   ----------------

   function To_F26Dot6 (X : FT_Pos) return FT_F26Dot6 is
      function Internal is new Ada.Unchecked_Conversion (FT_Pos, FT_F26Dot6);
   begin
      return Internal (X);
   end To_F26Dot6;

   --------------
   -- To_Fixed --
   --------------

   function To_Fixed (X : FT_Pos) return FT_Fixed is
      function Internal is new Ada.Unchecked_Conversion (FT_Pos, FT_Fixed);
   begin
      return Internal (X);
   end To_Fixed;

   --------------
   -- To_Array --
   --------------

   function To_Array
     (Ptr : FT_Vectors_Ptr;
      Length : FT_Int)
      return FT_Vector_Array
   is
   begin
      return Vector_Pointers.Value
        (Vector_Pointers.Pointer (Ptr), Interfaces.C.ptrdiff_t (Length));
   end To_Array;

   --------------
   -- To_Array --
   --------------

   function To_Array
     (Ptr : FT_Curve_Tags_Ptr;
      Length : FT_Int)
      return FT_Curve_Tag_Array
   is
   begin
      return Curve_Tag_Pointers.Value
        (Curve_Tag_Pointers.Pointer (Ptr), Interfaces.C.ptrdiff_t (Length));
   end To_Array;

   ------------------
   -- Get_Contours --
   ------------------

   function Get_Contours (Outline : FT_Outline) return FT_Short_Array is
   begin
      return To_Array (Outline.Contours, FT_Int (Outline.N_Contours));
   end Get_Contours;

   ----------------
   -- Get_Points --
   ----------------

   function Get_Points (Outline : FT_Outline) return FT_Vector_Array is
   begin
      return To_Array (Outline.Points, FT_Int (Outline.N_Points));
   end Get_Points;

   --------------
   -- Get_Tags --
   --------------

   function Get_Tags (Outline : FT_Outline) return FT_Curve_Tag_Array is
   begin
      return To_Array (Outline.Tags, FT_Int (Outline.N_Points));
   end Get_Tags;

   --------------
   -- To_Array --
   --------------

   function To_Array
     (Ptr : FT_Spans_Ptr;
      Length : FT_Int)
      return FT_Span_Array
   is
   begin
      return Span_Pointers.Value
        (Span_Pointers.Pointer (Ptr), Interfaces.C.ptrdiff_t (Length));
   end To_Array;



end FT2.Image;
